<!--
@author  tanyuze
@desc    打卡活动选择资源
@date    2022/11/10
-->
<template>
  <div class="clock-choose-data">
    <div class="table-data">
      <el-collapse-transition>
        <section class="main-search merge">
          <span class="svg-container">
            <svg-icon icon-class="search" />
          </span>
          <el-input v-model.trim="listQuery.name" placeholder="输入名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
          <section class="search-btn">
            <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
            <el-button type="primary" @click="handleReset">重置</el-button>
          </section>
        </section>
      </el-collapse-transition>
      <v-table
        v-if="tag"
        :list="tableData"
        :tag="tag"
        :height="440"
        :selection="true"
        :list-loading="listLoading"
        :filter-column="filterColumn"
        :source-arr="['subjectImgUrl', 'courseImgUrl', 'imgIdUrl', 'coverImgIdUrl']"
        @handleSelectionChange="handleSelectionChange"
      />
    </div>
    <div class="page">
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import { getResource } from '../api'
import Pagination from '@/components/Pagination'
import vTable from '@/components/Table'
export default {
  name: 'ChooseResource',
  components: { Pagination, vTable },
  props: {
    activeTab: {
      // 资源分类
      type: String,
      default: ''
    },
    areaId: {
      // 培训班id
      type: String,
      default: ''
    }
  },
  data() {
    return {
      listLoading: false,
      total: 0,
      tableData: [],
      listQuery: {
        page: 1,
        limit: 10
      },
      typeList: {
        RYTJ_ZDCG: {
          url: '/backend/rushQuestions/queryPage',
          name: '',
          tag: 'clockConfirm'
        },
        RYTJ_ZDDTHDPM:{
          url:'/backend/specialAnswers/queryPage',
          name:"",
          tag:"newSpecial",
        },
        RYTJ_ZDPX: {
          url: '/backend/areaDefinition/queryPage',
          name: '',
          tag: 'classList'
        },
        RYTJ_ZDZB: {
          url: '/backend/liveActivity/queryPage',
          liveName: '',
          tag: 'liveIndex'
        },
        RYTJ_ZDWJ: {
          url: '/backend/questionnaireSurvey/queryPage',
          name: '',
          tag: 'surveyMain'
        },
        RYTJ_ZDTP: {
          url: '/backend/votingInfo/queryPage',
          votingName: '',
          newsType: '',
          tag: 'vote'
        },
        tag: ''
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.tag = this.typeList[this.activeTab].tag
    this.getList()
  },
  methods: {
    handleSelectionChange(arr) {
      this.$emit('selectMany', arr)
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.name = ''
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        name: this.listQuery.name
      }
      /* if (this.activeTab === 'CLOCK_ZYLX_SP') {
        query['status'] = 'KCZT01'
        query['courseType'] = 'KCLX01'
        query['courseName'] = this.listQuery.name
      }
      if (this.activeTab === 'CLOCK_ZYLX_YP') {
        query['status'] = 'KCZT01'
        query['courseType'] = 'KCLX03'
        query['courseName'] = this.listQuery.name
      }
      if (this.activeTab === 'CLOCK_ZYLX_CG') {
        query['name'] = this.listQuery.name
      }*/
      const url = this.typeList[this.activeTab].url
      return new Promise((resolve, reject) => {
        getResource(url, query)
          .then((response) => {
            this.tableData = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    },

    filterColumn(scope, item) {
      return scope.row[item]
    }
  }
}
</script>

<style type="text/css" lang="scss">
.clock-choose-data {
  height: 550px;
  display: flex;
  flex-direction: column;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }
  }
  .table-data {
    flex: 1;
  }
  .page {
    height: 50px;
  }
}
</style>
